package com.party.mobile.web.controller.system;

import com.party.common.utils.PartyCode;
import com.party.common.utils.StringUtils;
import com.party.core.model.system.SysConfig;
import com.party.core.service.system.ISysConfigService;
import com.party.mobile.web.dto.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Description: 配置管理的控制器
 * @Author: yangshoukun
 * @Date: 2018/5/15 14:14
 */
@Controller
@RequestMapping("/system/config")
public class ConfigController {
    @Autowired
    private ISysConfigService sysConfigService;

    @ResponseBody
    @RequestMapping(value = "/findByCode")
    public AjaxResult findByCode(String code) {
        if (StringUtils.isEmpty(code)) {
            return AjaxResult.error(PartyCode.PARAMETER_ILLEGAL, "code不能为空");
        }
        SysConfig config = sysConfigService.findByCode(code);
        return AjaxResult.success(config);
    }


    /**
     * 是否需要验证短信
     *
     * @return 交互数据
     */
    @ResponseBody
    @RequestMapping(value = "/isVerifySms")
    public AjaxResult isVerifySms(){
        AjaxResult ajaxResult = new AjaxResult();
        boolean isVerify;
        try {
            isVerify = sysConfigService.isVerifySms();
        } catch (Exception e) {
            ajaxResult.setSuccess(false);
            ajaxResult.setDescription("系统异常");
            return ajaxResult;
        }
        ajaxResult.setSuccess(true);
        ajaxResult.setData(isVerify);
        return ajaxResult;
    }
}
